<template>
  <el-card class="wrap">
    <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="80px" class="demo-ruleForm">
      <el-form-item label="名称" prop="name">
        <el-input v-model="ruleForm.name" />
      </el-form-item>
      <el-form-item label="排序" prop="sort">
        <el-input-number v-model="ruleForm.sort" controls-position="right" step-strictly :min="1" :max="10">
        </el-input-number>
      </el-form-item>
      <el-form-item label="展示">
        <el-radio-group v-model="ruleForm.status">
          <el-radio label="0">隐藏</el-radio>
          <el-radio label="1">显示</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
        <el-button type="primary" @click="submitForm('ruleForm')">立即更新</el-button>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script>
export default {
  name: 'TagCreate',
  data() {
    return {
      ruleForm: {
        id: '',
        name: '',
        sort: 1,
        status: 1,
      },
      rules: {
        name: [{ required: true, message: '请输入分类名称', trigger: 'blur' }],
        sort: [{ required: true, message: '请输入分类排序', trigger: 'blur' }],
      },
    }
  },
  created() {
    this.getTag()
  },
  methods: {
    // 提交表单
    submitForm(formName) {
      this.updateTag()
    },
    // 获取分类信息
    async getTag() {
      this.ruleForm = this.$route.query
    },
    // 更新分类
    async updateTag() {
      const res = await this.$api.httpTagUpdate(this.ruleForm)
      const { code, data } = res
      if (code == 200) {
        this.$message.success('修改成功')
        this.$router.go(-1)
      }
    },
    // 重置表单
    resetForm(formName) {
      // this.$refs[formName].resetFields()
    },
  },
}
</script>

<style scoped lang="scss">
</style>
